# Vectors some_numbers <- c(30, 50, 60) some_numbers[c(2,3)] some_numbers > 3 some_numbers * 5
What is total_sum?
numbers <- 1:4
total_sum <- 0
n <- length(numbers)
# start loop
for (i in 1:n) {
if(i %% 2 == 0){
total_sum <- total_sum + numbers[i]
} else {
total_sum <- total_sum + 2*numbers[i]
}
}
Microprocessors can only represent two signs (states):
010, 1.What is the decimal number 139 in the binary counting frame?
What is the decimal number 139 in the binary counting frame?
\[(1 \times 2^7) + (1 \times 2^3) + (1 \times 2^1) + (1 \times 2^0) = 139.\]
What is the decimal number 139 in the binary counting frame?
\[(1 \times 2^7) + (1 \times 2^3) + (1 \times 2^1) + (1 \times 2^0) = 139.\]
\[(1 \times 2^7) + (0 \times 2^6) + (0 \times 2^5) + (0 \times 2^4) + (1 \times 2^3)\\ + (0 \times 2^2) + (1 \times 2^1) + (1 \times 2^0) = 139.\]
139 in the decimal system corresponds to 10001011 in the binary system.| Number | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
| Number | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| 0 = | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 = | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 2 = | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 3 = | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| … | ||||||||
| 139 = | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
# Subtracting two nearly identical floating-point numbers x <- 0.3 - 0.2 y <- 0.1 # Check if they are equal result <- x == y print(x)
## [1] 0.1
print(y)
## [1] 0.1
print(result)
## [1] FALSE
print(format(x, digits = 20)) # prints a more precise value of x
## [1] "0.099999999999999977796"
print(format(y, digits = 20)) # prints a more precise value of y
## [1] "0.10000000000000000555"
tolerance <- 1e-9 equal <- abs(x - y) < tolerance print(equal)
## [1] TRUE
If computers only understand 0 and 1, how can they express decimal numbers like 139?
If computers only understand 0 and 1, how can they express decimal numbers like 139?
0/1 switch).0-9 (used like in the decimal system)…A-F (for the numbers 10 to 15).0-9 (used like in the decimal system)…A-F (for the numbers 10 to 15).What is the decimal number 139 expressed in the hexadecimal system?
What is the decimal number 139 expressed in the hexadecimal system?
Solution: \[(8\times 16^1) + (11\times 16^0) = 139.\]
More precisely: \[(8\times 16^1) + (B\times 16^0) = 8B = 139.\]
10001011 (in binary) = 8B (in hexadecimal) = 139 in decimal.Advantages (when working with binary numbers)
WHY?
😆How can a computer understand text if it only understands 0s and 1s?
A modified version of South Korean Dubeolsik (two-set type) for old hangul letters. (Illustration by Yes0song 2010, Creative Commons Attribution-Share Alike 3.0 Unported)
How can a computer understand text if it only understands 0s and 1s?
0s and 1s correspond to specific letters/characters of different human languages.How can a computer understand text if it only understands 0s and 1s?
0s and 1s correspond to specific letters/characters of different human languages.ASCII logo. (public domain).
| Binary | Hexadecimal | Decimal | Character |
|---|---|---|---|
| 0011 1111 | 3F | 63 | ? |
| 0100 0001 | 41 | 65 | A |
| 0110 0010 | 62 | 98 | b |
Two core themes of this course:
Two core themes of this course:
In both of these domains we mainly work with one simple type of document: text files.
0s and 1s)!0s and 1s)!
Install RStudio from here!
Install Atom from here!
Install VScode from here!
Install Sublime text from here!
The ‘blackbox’ of data processing.
Basic components of a standard computing environment.
plyr, doParallel() and future
large_matrix <- matrix(1, nrow=1e8, ncol=1e8)
## Error in matrix(1, nrow = 1e+08, ncol = 1e+08): Vektor ist zu groß
Recall the initial example (survey) of this course.
Access a website (over the Internet), use keyboard to enter data into a website (a Google sheet in that case).
R program accesses the data of the Google sheet (again over the Internet), downloads the data, and loads it into RAM.
Data processing: produce output (in the form of statistics/plots), output on screen.
5468616E6B7320616E642073656520796F75206E657874207765656B21
🤓